package cn.zhang.test;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.log4j.spi.LoggerFactory;

import cn.zhang.entity.Person;
import cn.zhang.util.MyDateConverter;

public class BeanUtilsDemo {

	 //LoggerFactory.
	
	public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
		
		ConvertUtils.register(new MyDateConverter(),Date.class);
		
		Person p = new Person();
		
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", "2");
		map.put("usercode", "  admin  ");
		map.put("password", "admin");
		map.put("username", "管理员");
		map.put("money", "21.23");
		map.put("birthday", "2018-02-03");
		//map.put("birthday", new Date());
		//
		try {
			/*BeanUtils.setProperty(p, "id", "   ");
			BeanUtils.setProperty(p, "username", "   2   ");
			BeanUtils.setProperty(p, "money", "   2.202   ");
			BeanUtils.setProperty(p, "birthday", new Date());*/
			BeanUtils.populate(p, map);
		} catch (Exception e) {
			System.out.println("参数设定失败");
		}
		System.out.println(p);
		
		/*Person p2 = (Person) BeanUtils.cloneBean(p); 
		System.out.println( p == p2);*/
		
		Map m = BeanUtils.describe(p);
		System.out.println(m.toString());
	}
}
